<!doctype html>
<html lang="en">
 <head>
	<meta charset="UTF-8">
	<title>Equipment</title>
	<link rel="stylesheet" href="../js/easyui/themes/bootstrap/easyui.css">
	<link rel="stylesheet" href="../js/easyui/themes/icon.css">
	<link rel="stylesheet" href="../css/index-ui.css" />
	<script type="text/javascript" src="../js/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="../js/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../js/ams.util.js"></script>
	<script type="text/javascript" src="../js/webapi.js"></script>
</head>
<body onload="on_page_load()">
	<div style="background:#58585a"> <label id="eq_name_label"> {eq_name} </label> </div>
	<div id="top_panel" class="easyui-panel" style="padding:10px;background:#58585a" align="center">
    <a href="eq_overview.html" target="pane_main" class="easyui-linkbutton" style="width:110px" data-options="iconCls:'icon-eq',toggle:true,group:'g2',plain:false,selected:true">Overview</a>
    <a href="eq_recipe.html" target="pane_main" class="easyui-linkbutton" style="width:110px" data-options="iconCls:'icon-recipe',toggle:true,group:'g2',plain:false">Recipe</a>
    <a href="eq_config.html" target="pane_main" class="easyui-linkbutton" style="width:110px" data-options="iconCls:'icon-config',toggle:true,group:'g2',plain:false">Config</a>
    <a id="btn_alarm" class="easyui-menubutton" style="width:110px" data-options="menu:'#mm2',iconCls:'icon-alarm-disable',toggle:true,group:'g2',plain:false">Alarm</a>
    <a href="eq_data.html" target="pane_main" class="easyui-linkbutton" style="width:110px" data-options="iconCls:'icon-sum',toggle:true,group:'g2',plain:false">Data</a>
    <a href="eq_lotlog.html" target="pane_main" class="easyui-linkbutton" style="width:110px" data-options="iconCls:'icon-oplog',toggle:true,group:'g2',plain:false">LOT log</a>
		<!-- <a href="eq_oplog_eq.html" target="pane_main" class="easyui-linkbutton" style="width:140px" data-options="menu:'#mm1',iconCls:'icon-filter',toggle:true,group:'g2',plain:false">OP log(equipment)</a>
		<a href="eq_oplog_server.html" target="pane_main" class="easyui-linkbutton" style="width:120px" data-options="menu:'#mm1',iconCls:'icon-filter',toggle:true,group:'g2',plain:false">OP log(server)</a> -->
		<a class="easyui-menubutton" style="width:110px" data-options="menu:'#mm1',iconCls:'icon-filter',toggle:true,group:'g2',plain:false">OP log</a>
  	<a href="eq_stat.html" target="pane_main" class="easyui-linkbutton" style="width:110px" data-options="iconCls:'icon-stat',toggle:true,group:'g2',plain:false">Statistic</a>
  </div>
  <div id="mm1" style="width:50px">
	  <div onclick="OnOpLogSv()">OP log(Server)</div>
		<div onclick="OnOpLogEq()">OP log(Equipment)</div>
  </div>
  <div id="mm2" style="width:50px">
	  <div onclick="RealtimeAlarm()">Realtime Alarm</div>
		<div onclick="HistoryAlarm()">History Alarm</div>
  </div>
	<div class="eq_pane_main">
		<iframe scrolling="no" name="pane_main" src="eq_overview.html" frameborder="0">
			<!--src="overview/overview.html"-->
		</iframe>
	</div>
	<input type="hidden" id="eq_name">
</body>
<script language="javascript">
	var info = get_page_param("eq");
	var arrInfo = info.split("#");
	var eq_name = arrInfo[0];//get_page_param("eq");
	var grp_name = arrInfo[1];
	$("#eq_name").val(eq_name)
	document.getElementById("eq_name_label").innerText = "Equipment: " + eq_name;
	var children = document.getElementById('top_panel').childNodes
	for (var i = 0; i < children.length; i++) {
		if (children[i].href) {
			children[i].href = children[i].href + '?eq=' + eq_name
		}
	}
  
  function OnOpLogEq()
  {
  	pane_main.location.href ='eq_oplog_eq.html' + '?eq=' + eq_name
  }
  
  function OnOpLogSv()
  {
  	pane_main.location.href = 'eq_oplog_server.html' + '?eq=' + eq_name
  }
  
  var g_nNumber = 0;
  var g_bAlarm = false;
  
  function on_page_load(){
  	update();
  }
  
  function getEqFaRemote(eqType, faRemote)
	{
		var fa = "Unknown";
		if (parseInt(eqType) == 1){// S17109
			switch (parseInt(faRemote)) {
			case 0: // OffEquip
				fa = "OffEquip";
				break
			case 1: // OnLocal
				fa = "OnLocal";
				break
			case 2: // OnRemote
				fa = "OnRemote";
				break
			case 3: // OffHost
				fa = "OffHost";
				break
			}
		}else if(parseInt(eqType) == 2){// S17110
			switch (parseInt(faRemote)) {
			case 0: // OffEquip
				fa = "EQ-OFFL"
				break
			case 1: // OnLocal
				fa = "ATTP-ONL";
				break
			case 2: // OnRemote
				fa = "HOST-OFFL";
				break
			case 3: // OffHost
				fa = "LOCAL";
				break
			case 4:
				fa = "REMOTE";
				break
			}
		}
		return fa;
	}
	
  function getEqState(eqState)
	{
		var State = "";
		switch (parseInt(eqState)) {
		case -1: // offline
			State = "Offline";
			break
		case 0: // idle
			State = "Idle";
			break
		case 1: // running
			State = "Running";
			break
		case 2: // pausing
			State = "Pausing";
			break
		case 3: // paused
			State = "Paused";
			break
		case 4: // aborting
			State = "Aborting";
			break
		case 5: // disable
			State = "Disable";
			break
		case 6: // waiting
			State = "Waiting";
			break
		case 7: // error
			State = "Error";
			break
		default:
			alert('error: ' + eq.state)
			break
		}
		return State;
	}

  function changeButtonIcon(def){
  	if (g_bAlarm){
  		var almBtn = $("#btn_alarm");
      $("span", almBtn).each(function(){
      	if ($(this).hasClass('l-btn-icon')){
      		var add = $(this).hasClass('icon-alarm-enable');
      		$(this)[add ? 'removeClass' : 'addClass']('icon-alarm-enable')[add ? 'addClass' : 'removeClass']('icon-alarm-disable');
      		return;
      	}
      });
  	}
  	else{
  		if (def == true){
  			var almBtn = $("#btn_alarm");
			  $("span", almBtn).each(function(){
      	if ($(this).hasClass('l-btn-icon')){
      		$(this)['addClass']('icon-alarm-disable')['removeClass']('icon-alarm-enable');
      		return;
	      	}
	      });
    	}
  	}
  }
  
  function update()
	{
		if (ams_is_sim_mode()) {
		}
		else{
			if (g_nNumber == 0){
					$.ajax({
					type: 'POST',
					contentType: 'application/json',
					url: getWebServiceUrl("getGroupEqInfo"),
					data:JSON.stringify({
						"groupName": grp_name
					}),
					dataType: 'json',
					success: function (json_data) {
						var data = JSON.parse(json_data.d);
						for (var i = 0; i < data.eq_array.length; i++){
							if (data.eq_array[i].name == eq_name){
								var info = "<font style=\"font-size: 18pt\" color='blue'>Equipment: " + "</font>" + eq_name;
								if (data.eq_array[i].alarm == 0){
									g_bAlarm = false;
									changeButtonIcon(true);
								}
								else{
									g_bAlarm = true;
								}
								info += "<font style=\"font-size: 18pt\" color='blue'>   State: " + "</font>" + getEqState(data.eq_array[i].state);
								info += "<font style=\"font-size: 18pt\" color='blue'>   Fa: " + "</font>" + getEqFaRemote(data.eq_array[i].type, data.eq_array[i].fa);
								//document.getElementById("eq_name_label").innerText = info;
								document.getElementById("eq_name_label").innerHTML = info;
								break;
							}
						}						
					},
					error: function (response) {					
						//alert('Error: ' + response.responseText)
						console.log('Error: ' + response.responseText)
					}
				});
			}
			
			changeButtonIcon(false);
			if (g_nNumber > 5){
				g_nNumber = 0;
			}
			else{
				g_nNumber++;
			}
		}
	setTimeout('update()', 1000)
}

function RealtimeAlarm()
{
	pane_main.location.href ='eq_alarm_realtime.html' + '?eq=' + eq_name
}

function HistoryAlarm()
{
	 pane_main.location.href ='eq_alarm_history.html' + '?eq=' + eq_name
}
</script>
</html>
